import java.util.Scanner;

/**
 * 用户服务
 *
 * @author yuwei
 * @date 15:31 2024/4/24
 */
public class departmentManage {
    public static void add()
    {
        System.out.println("--添加部门--");
        System.out.println("输入部门名称");
        Scanner scan = new Scanner(System.in);
        if (departmentTable.departments.add(new Department(scan.next())))
        {
            System.out.println("添加成功");
        }
        else
        {
            System.out.println("添加失败,该部门可能已经存在");
        }
    }

    public static void show() {
        if(departmentTable.departments.size()==0){
            System.out.println("    无任何数据 ");
            return;
        }
        departmentTable.departments.forEach(System.out::println);
    }
    public static void delete(){
        System.out.println("--删除部门--");
        System.out.println("部门名称");
        if(departmentTable.departments.size()==0){
            System.out.println("    无任何数据 ");
            return;
        }
        for(int i = 1;i<=departmentTable.departments.size();i++){
            System.out.println(i+". "+departmentTable.departments.toArray()[i-1]);
            if(i==departmentTable.departments.size()){
                System.out.println("输入要删除的部门编号");
                Scanner scan = new Scanner(System.in);
                int index = scan.nextInt();
                if(index<=departmentTable.departments.size()&&index>0){
                    Department tem = (Department) departmentTable.departments.toArray()[index-1];
                    if(positionManage.find(tem.getDepartment_name()))
                    {
                        System.out.println("该部门下还有职位，请先删除职位");
                        return;
                    }

                    departmentTable.departments.remove(tem);

                    System.out.println("删除成功");
                }
                else{
                    System.out.println("输入错误");
                }
            }
        }
    }
}
